/*
 * Copyright (c) 2009 Robert Esser
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.e2ser.component;

import android.graphics.Canvas;
import android.graphics.Rect;
import net.e2ser.petri.Editor;
import net.e2ser.petri.RobPoint;


/**
 *
 * <p>Title: Petri Net Editor/Simulator</p>
 * <p>Description: Represents the root of the net</p>
 * <p>Copyright: Copyright (c) 2009</p>
 * <p>Company: </p>
 * @author Rob Esser
 * @version 1.0
 */
public class RootNode extends RobComponent {
// the top node of any diagram is always a RootNode

  Editor editor = null;

  public RootNode() {
    this(null);
  }

  public RootNode(Editor editor) {
    super(null, 0, 0);
    this.editor = editor;
  }

  public void editor(Editor editor) {
    this.editor = editor;
  }

  public RobComponent topNode() {
    // return the root node
    return this;
  }

  /**
   * draw myself on the Canvas
   * @param canvas where to draw
   */
  public void draw(Canvas canvas) {
    // do nothing
  }

  public RobPoint connectionPoint(RobPoint otherEnd) {
    // do nothing
    return new RobPoint(0, 0);
  }

  public void changed(AbstractComponent comp) {
    Rect r = comp.bounds();
    //as this is called from the simulator thread we need to use postInvalidate
    editor.postInvalidate(r.left, r.top, r.right, r.bottom);
  }

}
